package com.example.kdxf08;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.iflytek.speech.SpeechError;
import com.iflytek.speech.SynthesizerPlayer;
import com.iflytek.speech.SynthesizerPlayerListener;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    private StringBuffer sb = new StringBuffer();

    public void show(View view) {
        SynthesizerPlayer player = SynthesizerPlayer.createSynthesizerPlayer(
                MainActivity.this,"appid=5212ef0a");
        player.setVoiceName("vixm");
        player.playText("七品茶诗,一晚吼吻润,二晚破古们", null, new SynthesizerPlayerListener() {
            @Override
            public void onPlayBegin() {

            }

            @Override
            public void onBufferPercent(int i, int i1, int i2) {

            }

            @Override
            public void onPlayPaused() {

            }

            @Override
            public void onPlayResumed() {

            }

            @Override
            public void onPlayPercent(int i, int i1, int i2) {

            }

            @Override
            public void onEnd(SpeechError speechError) {

            }
        });



        /*//弹出语音识别窗口
        RecognizerDialog dialog = new RecognizerDialog(MainActivity.this, "appid=5212ef0a");
        dialog.setListener(new RecognizerDialogListener() {
            //识别回调
            @Override
            public void onResults(ArrayList<RecognizerResult> arrayList, boolean b) {
                for (RecognizerResult result : arrayList) {
                    sb.append(result.text);
                }
            }

            //当识别完调用
            @Override
            public void onEnd(SpeechError speechError) {
                if (speechError == null){
                    System.out.println(sb.toString());
                }
                sb.setLength(0);
            }
        });
        dialog.show();*/

    }
}
